<?php
/**
 * The Activity form, used for creation and edition
 * @package ModuleOrganisationCommunication
 * @version 1.0b
 */
?>

<form action="" method ="post" class="form-crud">
<table cellpadding="0" cellspacing="0" border="0" class="form">
	<tr>
		<td class="form-crud-label" colspan="4"><h3 class="subtitle"><?php echo ($_GET['operation'] == 'edit') ? 'Activité '.$activity->title : 'Nouvelle Activité'; ?></h3></td>
	<tr>
	<tr>
		<td class="form-crud-label"><label for="activity-type">Type :</label></td>
		<td class="form-crud-input">
			<select id="activity-type" name="activity-type">
				<?php
				foreach ($activityType as $key => $item)
					echo '<option value="'.$key.'"'.(($activity->type == $key) ? ' selected="selected"' : '').'>'.$item.'</option>';
				?>
			</select>
		</td>
		<td class="form-crud-label"><label for="activity-status">Status :</label></td>
		<td class="form-crud-input">
			<select id="activity-status" name="activity-status">
				<?php
				foreach ($status as $key => $item)
					echo '<option value="'.$key.'"'.(($activity->status == $key) ? ' selected="selected"' : '').'>'.$item.'</option>';
				?>
			</select>
		</td>
	</tr>
	<tr>
		<td class="form-crud-label"><label for="activity-priority">Priorité :</label></td>
		<td class="form-crud-input">
			<select id="activity-priority" name="activity-priority">
				<?php
				foreach ($priority as $key => $item)
					echo '<option value="'.$key.'"'.(($activity->priority == $key) ? ' selected="selected"' : '').'>'.$item.'</option>';
				?>
			</select>
		</td>
		<td class="form-crud-label"><label for="activity-progress">% Effectué :</label></td>
		<td class="form-crud-input">
			<select id="activity-progress" name="activity-progress">
				<option value="0"<?php if ($activity->progress == '0') echo ' selected="selected"'; ?>>0%</option>
				<option value="25"<?php if ($activity->progress == '25') echo ' selected="selected"'; ?>>25%</option>
				<option value="50"<?php if ($activity->progress == '50') echo ' selected="selected"'; ?>>50%</option>
				<option value="75"<?php if ($activity->progress == '75') echo ' selected="selected"'; ?>>75%</option>
				<option value="100"<?php if ($activity->progress == '100') echo ' selected="selected"'; ?>>100%</option>
			</select>
		</td>
	</tr>
	<tr>
		<td class="form-crud-label"><label for="activity-contact">Contact :</label></td>
		<td class="form-crud-input"><input id="activity-contact" type="text" name="activity-contact" value="<?php echo $contact->lastname.' '.$contact->firstname; ?>" readonly="readonly" /></td>
		<td class="form-crud-label"><label for="activity-owner">Proriétaire :</label></td>
		<td class="form-crud-input"><input id="activity-owner" type="text" name="activity-owner" value="<?php echo $crmcontact->lastname.' '.$crmcontact->firstname; ?>" readonly="readonly" /></td>
	</tr>
	<tr>
		<td class="form-crud-label"><label for="activity-date">Date :</label></td>
		<td class="form-crud-input"><input id="activity-date" type="text" name="activity-date" value="<?php echo $date; ?>" readonly="readonly" /></td>
		<td class="form-crud-label"><label for="activity-hour">Heure :</label></td>
		<td class="form-crud-input"><input id="activity-hour" type="text" name="activity-hour" value="<?php echo $hour; ?>" /></td>
	</tr>
	<tr>
		<td class="form-crud-label"><label for="activity-title">Sujet :</label></td>
		<td class="form-crud-input" colspan="3"><input id="activity-title" type="text" name="activity-title" value="<?php echo $activity->title; ?>" /></td>
	</tr>
	<tr>
		<td class="form-crud-label" colspan="4"><h3 class="subtitle">Description</h3></td>
	<tr>
	<tr>
		<td class="form-crud-input" colspan="4">
			<textarea id="activity-content" rows="10" cols="10" name="activity-content"><?php echo $activity->content; ?></textarea>
		</td>
	</tr>
</table>
<br />
<input type="hidden" value="<?php echo $activity->contactId; ?>" name="activity-contactId" />
<input type="hidden" value="<?php echo $activity->crmuserId; ?>" name="activity-ownerId" />
<input type="hidden" value="<?php echo $activity->activityId; ?>" name="activity-activityId" />
<input type="hidden" value="<?php echo $_GET['operation']; ?>" name="activity-operation" />
<a href="#" id="form-activity" class="submit">Sauvegarder</a>

<?php if ($_GET['operation'] != 'add'): ?>
<table cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td class="form-crud-label" colspan="4"><h3 class="subtitle">Documents</h3></td>
	<tr>
	<tr>
		<td class="form-crud-label"></td>
		<td class="form-crud-input">
			<table cellpadding="0" cellspacing="0" border="0" class="documents">
			<?php
			$documentList = $activity->GetDocumentList();
			foreach ($documentList as $document) {
				$res  = '<tr>';
				$res .= '<td class="del"><a href="'.$document->documentId.'" class="delete-doc"><img src="css/img/bin_empty.png" alt="Delete" /></a></td>';
				$res .= '<td><a href="'.$configuration['appdir'].'data/docs/'.$document->documentId.'.'.$document->extension.'" target="_blank" class="file">'.$document->filename.'.'.$document->extension.'</a></td>';
				$res .= '</tr>';
				echo $res;
			}
			?>
			</table>
		</td>
		<td class="form-crud-label"></td>
		<td class="form-crud-input"></td>
	</tr>
	<tr>
		<td class="form-crud-label"><label for="activity-file-upload">Ajouter des fichiers :</label></td>
		<td class="form-crud-input"><input id="activity-file-upload" name="activity-file-upload" type="file" /></td>
		<td class="form-crud-label"></td>
		<td class="form-crud-input"></td>
	</tr>
	<tr>
		<td class="form-crud-label"></td>
		<td class="form-crud-input"><a href="javascript:$('#activity-file-upload').uploadifyUpload()" class="upload">Upload</a></td>
		<td class="form-crud-label"></td>
		<td class="form-crud-input"></td>
	</tr>
</table>
<?php endif; ?>

</form>

<div id="result"></div>

<div id="select_contact" class="hidden"></div>
<div id="select_crmuser" class="hidden"></div>